﻿/*
 * VoidTransform
 * 
 * initial implementation : 20.11.2008
 *
 * Copyright (c) Adam Sida, asida@centrum.cz.
 * All rights reserved.
 * 
 * for license see Petra.Gis.License.txt
 */
using System;
using System.Runtime.Serialization;
using Petra.Gis.Geometry.Support;


namespace Petra.Gis.ReferenceSystemServices.Transformations
{

  /// <summary>
  /// Void, empty, foo transform when both source and target coordsystems are same.
  /// Do nothing instead of computation  ;-)
  /// </summary>
  [DataContract]
  public class VoidTransform : SRSTransform
  {

    /// <summary>
    /// xaml constr.
    /// </summary>
    public VoidTransform() 
    {
      Metadata = new Metadata("void transformation, leave coordinates untouched", "none", -1, "", "", "empty or void transformation between exactly same Coordinate systems where no transform is needed");
    }




    public VoidTransform(CoordinateSystem sourceCS, CoordinateSystem targetCS)
      : this(sourceCS, targetCS, false) { }




    public VoidTransform(CoordinateSystem sourceCS, CoordinateSystem targetCS, bool createInverse)
      : base(sourceCS, targetCS)
    {
      IsInverse = createInverse;
      Metadata = new Metadata("void transformation, leave coordinates untouched", "none", -1, "", "", "empty or void transformation between exactly same Coordinate systems where no transform is needed");
    }





    /// <summary>
    /// leaves coordinate untouched, just returns original coordinate
    /// </summary>
    /// <param name="point"><c>ICoordinate</c> to transform</param>
    protected override void transform(ICoordinate point)
    {

    }




    /// <summary>
    /// returns inverse transformation, that is same as original
    /// as this transform does nothing with coordinates
    /// </summary>
    /// <returns>inverse transformation</returns>
    public override SRSTransform Inverse()
    {
      return new VoidTransform(Source, Target, !IsInverse);
    }



    /// <summary>
    /// VoidTransform is inversible, returns true
    /// </summary>
    public override bool IsInversible 
    {
      get { return true; }
    }





    /// <summary>
    /// VoidTransform can be used in 2D or 3D space. This property returns
    /// Dimension.dim2D to signalize that transform can be used also in 2D space.
    /// </summary>
    public override Dimension TransformDimension 
    {
      get { return Dimension.dim2D;} 
    }





    protected override void updateTransform()
    {

      if (Source.GetType() != Target.GetType())
        throw new ArgumentException("invalid operation, source and target Coordinate systems are not of same type");

      if (!Source.EqualParams(Target, CsCompareType.CompareAllParams))
        throw new ArgumentException("invalid operation, source and target Coordinate systems are not exactly same");      
    }




    protected override bool graphCompleted()
    {
      //nothing extra to check
      return true;
    }

  }

}
